package com.datang.pet.common.mergeUtils;
/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-05-14 15:23
 * @notify 视频合成处理类
 * @version 1.0
 */

import com.datang.pet.common.properties.MergeAttr;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class MergeVideoMp3 {


    public static void convertor(String videoInput,String audioInput,Double time, String output) throws Exception{
        //ffmpeg -i a.mp4 -i b.mp3 -vcodec copy -acodec copy  -t 10 c.mp4
        List<String> command = new ArrayList<>();
        command.add(MergeAttr.FFMPEGPATH);

        command.add("-i");
        command.add(videoInput);

        command.add("-i");
        command.add(audioInput);

        command.add("-t");
        command.add(time.toString());

        command.add(MergeAttr.TEMPORARYPath + output);

            ProcessBuilder builder = new ProcessBuilder(command);
            Process process = builder.start();
            InputStream errorStream = process.getErrorStream();
            InputStreamReader inputStreamReader = new InputStreamReader(errorStream);
            BufferedReader br = new BufferedReader(inputStreamReader);

            String line = "";
            while ((line = br.readLine()) != null) {
            }

            if (br != null) {
                br.close();
            }
            if (inputStreamReader != null) {
                inputStreamReader.close();
            }
            if (errorStream != null) {
                errorStream.close();
            }
    }


}
